# 判断两个字符串是否是“同素异形体”
def is_anagram(s, t):
    # 定义字典（哈希表）
    count_s_chars = {}
    count_t_chars = {}

    # 遍历两个字符串，统计他们出现的次数
    for char in s:
        if char in count_t_chars:
            count_t_chars[char] += 1
        else:
            count_t_chars[char] = 1
    for char in t:
        if char in count_s_chars:
            count_s_chars[char] += 1
        else:
            count_s_chars[char] = 1

    # 判断两字典是否一样，如果一样说明它们是“同素异形体”
    if count_s_chars == count_t_chars:
        return True

    return False

s1 = "anagram"
t1 = "nagaram"
print(is_anagram(s1, t1))

s2 = "rat"
t2 = "car"
print(is_anagram(s2, t2))